define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'echarts', 'echarts-theme'], function ($, undefined, Backend, Table, Form, Template, Echarts) {
    var Controller = {
        index: function () {
            //这句话在多选项卡统计表时必须存在，否则会导致影响的图表宽度不正确
            $(document).on("click", ".charts-custom a[data-toggle=\"tab\"]", function () {
                var that = this;
                setTimeout(function () {
                    var id = $(that).attr("href");
                    var chart = Echarts.getInstanceByDom($(id)[0]);
                    chart.resize();
                }, 0);
            });

            //初始加载
            ajax_roi();// ROI
            ajax_net_profit();//毛利
            ajax_sales();//销售
            ajax_ranking();//分配
            $("#statistics").click(function(){
                ajax_roi();// ROI
                ajax_net_profit();//毛利
                ajax_sales();//销售
                ajax_ranking();//分配
            });
            function ajax_roi(){
                var time_statistics = $("#time_statistics").val();
                Fast.api.ajax({
                    url: "fbchart/ajax_roi",
                    async: false,
                    data: {time: time_statistics}
                }, function (data) {
                    // 基于准备好的dom，初始化echarts实例
                    var lineChart = Echarts.init(document.getElementById('line-chart'));
                    // 指定图表的配置项和数据
                    option = {
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'shadow'
                            }
                        },
                        legend: {
                            data: ['张书凡', '敖辉', '邹洋', '黄彬', '付齐']
                        },
                        grid: {
                            left: '3%',
                            right: '4%',
                            bottom: '3%',
                            containLabel: true
                        },
                        xAxis: [
                            {
                                type: 'category',
                                data: ['2022-02-11', '2022-02-14', '2022-02-18', '2022-02-19', '2022-02-21']
                            }
                        ],
                        yAxis: {
                            type: 'value'
                        },
                        series: [
                            {
                                name: '张书凡',
                                type: 'bar',
                                stack: 'Ad',
                                emphasis: {
                                    focus: 'series'
                                },
                                data: ['4.1', '4.1', '4.1', '4.1', '4.1', '4.1', '4.1']
                            },
                            {
                                name: '敖辉',
                                type: 'bar',
                                stack: 'Ad',
                                emphasis: {
                                    focus: 'series'
                                },
                                data: ['4.1', '4.1', '4.1', '4.1', '4.1', '4.1', '4.1']
                            },
                            {
                                name: '邹洋',
                                stack: 'Ad',
                                type: 'bar',
                                emphasis: {
                                    focus: 'series'
                                },
                                data: ['4.1', '4.1', '4.1', '4.1', '4.1', '4.1', '4.1']
                            },
                            {
                                name: '黄彬',
                                type: 'bar',
                                stack: 'Ad',
                                emphasis: {
                                    focus: 'series'
                                },
                                data: ['4.1', '4.1', '4.1', '4.1', '4.1', '4.1', '4.1']
                            },
                            {
                                name: '付齐',
                                type: 'bar',
                                stack: 'Ad',
                                emphasis: {
                                    focus: 'series'
                                },
                                data: ['4.1', '4.1', '4.1', '4.1', '4.1', '4.1', '4.1']
                            }
                        ],
                    };
                    // 使用刚指定的配置项和数据显示图表。
                    lineChart.setOption(option);
                    return false;
                });
            };
            function ajax_net_profit(){
                var time_statistics = $("#time_statistics").val();
                Fast.api.ajax({
                    url: "fbchart/ajax_net_profit",
                    async: false,
                    data: {time: time_statistics}
                }, function (data) {
                    var barChart = Echarts.init(document.getElementById('simplebar-chart'));
                    option = {
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {            // Use axis to trigger tooltip
                                type: 'shadow'        // 'shadow' as default; can also be 'line' or 'shadow'
                            }
                        },
                        legend: {
                            data: ['张书凡', '敖辉', '邹洋', '黄彬', '付齐']
                        },
                        grid: {
                            left: '3%',
                            right: '4%',
                            bottom: '3%',
                            containLabel: true
                        },
                        xAxis: {
                            type: 'value'
                        },
                        yAxis: {
                            type: 'category',
                            data: ['2022-02-11', '2022-02-14', '2022-02-18', '2022-02-19', '2022-02-21']
                        },
                        series: [
                            {
                                name: '张书凡',
                                type: 'bar',
                                stack: 'total',
                                label: {
                                    show: true
                                },
                                emphasis: {
                                    focus: 'series'
                                },
                                data: ['12312','12312','12312','12312','12312','12312','12312']
                            },{
                                name: '敖辉',
                                type: 'bar',
                                stack: 'total',
                                label: {
                                    show: true
                                },
                                emphasis: {
                                    focus: 'series'
                                },
                                data: ['12312','12312','12312','12312','12312','12312','12312']
                            },{
                                name: '邹洋',
                                type: 'bar',
                                stack: 'total',
                                label: {
                                    show: true
                                },
                                emphasis: {
                                    focus: 'series'
                                },
                                data: ['12312','12312','12312','12312','12312','12312','12312']
                            },{
                                name: '黄彬',
                                type: 'bar',
                                stack: 'total',
                                label: {
                                    show: true
                                },
                                emphasis: {
                                    focus: 'series'
                                },
                                data: ['12312','12312','12312','12312','12312','12312','12312']
                            },{
                                name: '付齐',
                                type: 'bar',
                                stack: 'total',
                                label: {
                                    show: true
                                },
                                emphasis: {
                                    focus: 'series'
                                },
                                data: ['122','312','2312','1212','1312','1212','1312']
                            },
                        ]
                    };
                    barChart.setOption(option);
                    return false;
                });
            };
            function ajax_sales(){
                var time_statistics = $("#time_statistics").val();
                Fast.api.ajax({
                    url: "fbchart/ajax_sales",
                    async: false,
                    data: {time: time_statistics}
                }, function (data) {
                    var barChart = Echarts.init(document.getElementById('smoothline-chart'));
                    option = {
                        tooltip: {
                            trigger: 'axis'
                        },
                        legend: {
                            data: ['店铺1', '店铺2', '店铺3', '店铺4']
                        },
                        grid: {
                            left: '3%',
                            right: '4%',
                            bottom: '3%',
                            containLabel: true
                        },
                        toolbox: {
                            feature: {
                                saveAsImage: {}
                            }
                        },
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: ['2022-02-11', '2022-02-14', '2022-02-18', '2022-02-19', '2022-02-21']
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [
                            {
                                name: '店铺1',
                                type: 'line',
                                stack: 'Total',
                                data: [120, 132, 101, 134, 90, 230, 210]
                            },
                            {
                                name: '店铺2',
                                type: 'line',
                                stack: 'Total',
                                data: [220, 182, 191, 234, 290, 330, 310]
                            },
                            {
                                name: '店铺3',
                                type: 'line',
                                stack: 'Total',
                                data: [150, 232, 201, 154, 190, 330, 410]
                            },
                            {
                                name: '店铺4',
                                type: 'line',
                                stack: 'Total',
                                data: [320, 332, 301, 334, 390, 330, 320]
                            }
                        ],
                    };
                    barChart.setOption(option);
                    return false;
                });
            };
            function ajax_ranking(){
                var time_statistics = $("#time_statistics").val();
                Fast.api.ajax({
                    url: "fbchart/ajax_ranking",
                    async: false,
                    data: {time: time_statistics}
                }, function (data) {
                    var barChart = Echarts.init(document.getElementById('bar-chart'));
                    option = {
                        legend: {},
                        tooltip: {},
                        dataset: {
                            source: [
                                ['销售员', '张书凡', '敖辉', '邹洋', '黄彬', '付齐'],
                                ['店铺1', 43.3, 85.8, 93.7, 85.8, 93.7],
                                ['店铺2', 83.1, 73.4, 55.1, 85.8, 86.7],
                                ['店铺3', 86.4, 65.2, 82.5, 72.8, 93.7],
                                ['店铺4', 72.4, 53.9, 39.1, 86.8, 72.7]
                            ]
                        },
                        xAxis: {type: 'category'},
                        yAxis: {},
                        // Declare several bar series, each will be mapped
                        // to a column of dataset.source by default.
                        series: [
                            {type: 'bar'},
                            {type: 'bar'},
                            {type: 'bar'},
                            {type: 'bar'},
                            {type: 'bar'}
                        ]
                    };
                    // 使用刚指定的配置项和数据显示图表。
                    barChart.setOption(option);
                    return false;
                });
            };
        }
    };
    return Controller;
});
